package com.gzc.just.play.last.war.sceneserver.network.broadcast;

import com.google.protobuf.Message;

/**
 * 广播消息 - 用于TCP网络广播
 * 
 * 映射自C++ SSBattle::BroadMsgToGC
 * 包含消息内容和目标信息
 * 
 * @author AI编程助手
 * @version 1.0
 */
public class BroadcastMessage {
    
    /**
     * 广播类型
     */
    public enum BroadcastType {
        /**
         * 广播到所有战斗参与者（包括观众）
         */
        BROADCAST_TO_ALL,
        
        /**
         * 广播到特定战斗的所有玩家
         */
        BROADCAST_TO_BATTLE,
        
        /**
         * 广播到特定队伍
         */
        BROADCAST_TO_TEAM,
        
        /**
         * 发送给特定玩家
         */
        SEND_TO_PLAYER
    }
    
    private long messageId;
    private long timestamp;
    private BroadcastType broadcastType;
    private Message protoMessage;
    private int messageTypeId;
    
    // 目标信息
    private long battleId;
    private int teamId = -1;
    private long targetPlayerId = -1;
    
    // 优先级和可靠性
    private int priority = 0;
    private boolean reliable = true;
    
    /**
     * 构造函数 - 广播到所有玩家
     * 
     * @param battleId 战斗ID
     * @param protoMessage 协议缓冲区消息
     * @param messageTypeId 消息类型ID
     */
    public BroadcastMessage(long battleId, Message protoMessage, int messageTypeId) {
        this(battleId, BroadcastType.BROADCAST_TO_BATTLE, protoMessage, messageTypeId);
    }
    
    /**
     * 构造函数
     * 
     * @param battleId 战斗ID
     * @param broadcastType 广播类型
     * @param protoMessage 协议缓冲区消息
     * @param messageTypeId 消息类型ID
     */
    public BroadcastMessage(long battleId, BroadcastType broadcastType, 
                           Message protoMessage, int messageTypeId) {
        this.messageId = System.nanoTime();
        this.timestamp = System.currentTimeMillis();
        this.battleId = battleId;
        this.broadcastType = broadcastType;
        this.protoMessage = protoMessage;
        this.messageTypeId = messageTypeId;
    }
    
    /**
     * 获取消息ID
     * 
     * @return 消息ID
     */
    public long getMessageId() {
        return messageId;
    }
    
    /**
     * 获取时间戳
     * 
     * @return 时间戳（毫秒）
     */
    public long getTimestamp() {
        return timestamp;
    }
    
    /**
     * 获取广播类型
     * 
     * @return 广播类型
     */
    public BroadcastType getBroadcastType() {
        return broadcastType;
    }
    
    /**
     * 获取协议缓冲区消息
     * 
     * @return Protobuf消息
     */
    public Message getProtoMessage() {
        return protoMessage;
    }
    
    /**
     * 获取消息类型ID
     * 
     * @return 消息类型ID
     */
    public int getMessageTypeId() {
        return messageTypeId;
    }
    
    /**
     * 获取战斗ID
     * 
     * @return 战斗ID
     */
    public long getBattleId() {
        return battleId;
    }
    
    /**
     * 获取队伍ID
     * 
     * @return 队伍ID（-1表示无效）
     */
    public int getTeamId() {
        return teamId;
    }
    
    /**
     * 设置队伍ID
     * 
     * @param teamId 队伍ID
     */
    public void setTeamId(int teamId) {
        this.teamId = teamId;
    }
    
    /**
     * 获取目标玩家ID
     * 
     * @return 玩家ID（-1表示无效）
     */
    public long getTargetPlayerId() {
        return targetPlayerId;
    }
    
    /**
     * 设置目标玩家ID
     * 
     * @param targetPlayerId 玩家ID
     */
    public void setTargetPlayerId(long targetPlayerId) {
        this.targetPlayerId = targetPlayerId;
    }
    
    /**
     * 获取优先级
     * 
     * @return 优先级（0表示默认）
     */
    public int getPriority() {
        return priority;
    }
    
    /**
     * 设置优先级
     * 
     * @param priority 优先级
     */
    public void setPriority(int priority) {
        this.priority = priority;
    }
    
    /**
     * 是否可靠传输
     * 
     * @return 是否可靠
     */
    public boolean isReliable() {
        return reliable;
    }
    
    /**
     * 设置可靠性
     * 
     * @param reliable 是否可靠
     */
    public void setReliable(boolean reliable) {
        this.reliable = reliable;
    }
    
    @Override
    public String toString() {
        return String.format("BroadcastMessage{id=%d, type=%s, battleId=%d, msgTypeId=%d}", 
                           messageId, broadcastType, battleId, messageTypeId);
    }
}
